<template>
  <view class="page">
    <u-navbar
      :is-back="false"
      title="我的"
      title-color="#000"
      title-size="38"
      :border-bottom="false"
    >
    </u-navbar>
    <view class="logout btn" @click="show = true"> 退出 </view>
    <view class="logout btn" @click="toPage('subUserAdd')">子账号管理</view>
    <!-- #ifdef MP-WEIXIN -->
    <view class="logout btn" @click="wechatLogin()"> 绑定微信 </view>
    <!-- #endif -->
    <view class="logout btn" @click="toPage('monitoringPlugin')">
      监控插件
    </view>
    <u-toast ref="uToast" />
    <u-modal
      ref="uModel"
      v-model="show"
      :content="content"
      @confirm="logout()"
      :show-cancel-button="true"
    />
  </view>
</template>

<script>
import { bindMiniApp } from "@/api/user.js";
export default {
  data() {
    return {
      show: false,
      content: "确定要退出登录吗?",
    };
  },
  methods: {
    logout() {
      uni.clearStorageSync();
      uni.reLaunch({ url: "/pages/login/login" });
    },
    toPage(url) {
      uni.navigateTo({
        url: "/pages/" + url + "/" + url,
      });
    },
    // 微信登录
    wechatLogin() {
      uni.login({
        provider: "weixin",
        success: (loginRes) => {
          let code = loginRes.code;
          bindMiniApp(code).then((res) => {
            console.log(res);
            this.$refs.uToast.show({
              title: res.data.msg,
              type: "success",
              position: "bottom",
            });
          });
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.page {
  height: 100%;

  height: calc(100vh - 60px - var(--status-bar-height));

  background: #f8f8f8;
}

.logout {
  width: 480rpx;
  height: 88rpx;
  background: #ffffff;
  box-shadow: 0rpx 6rpx 18rpx rgba(153, 153, 153, 0.2);
  border-radius: 42rpx;
  font-size: 32rpx;
  color: #ff0000;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 100rpx auto;
}
</style>
